namespace Warehouse

open System
open System.Windows.Data
open Warehouse
open FSharp.Windows
open Warehouse.Controls

module InvoicesAndPOsReport = 

    [<AbstractClass>]
    type ReportModel() = 
        inherit Model()

        abstract Title : string with get, set
        abstract From : DateTime with get, set
        abstract To : DateTime with get, set
        abstract CompanyLookup : string list with get, set
        abstract SelectedCompany : string with get, set

    type ReporView() as this = 
        inherit FSharp.Windows.StaticView<ReportModel, InvoicesAndPOsReportWindow>()
    
        do 
            this.DefaultOKButton <- this.Control.OK

        override this.SetBindings model =
            Binding.TwoWay
                <@
                    this.Control.From.Text <- string model.From
                    this.Control.To.Text <- string model.To
                @>

            Binding.FromExpression 
                <@
                    this.Control.Title <- model.Title
                    this.Control.Company.ItemsSource <- model.CompanyLookup
                    this.Control.Company.SelectedItem <- model.SelectedCompany
                @>        
      
    [<AbstractClass>]      
    type ReportController(repository : DataModel.Repository, title) = 
        inherit StaticViewController<ReportModel>()

        abstract Companies : string list with get 

        override this.InitModel model = 
            model.Title <- title
            model.From <- DateTime.Now
            model.To <- DateTime.Now
            model.CompanyLookup <- "All" :: this.Companies
            model.SelectedCompany <- "All"

    type ClientInvoicesController(repository) = 
        inherit ReportController(repository, "Invoice report")

        override this.Companies = [ for x in repository.Clients -> x.CompanyName ]

    type VendorPOsController(repository) = 
        inherit ReportController(repository, "Vendor purchase orders")

        override this.Companies = [ for x in repository.Vendors -> x.CompanyName ]
        